<?php
header("Content-type: text/javascript; charset=utf8");

include_once "config.php";

define( "D_FOLDER", "styles/" );
define( "D_SITE", "http://ok.onlife.mobi/".D_FOLDER );

$ret = array("error"=>0);

$db->real_query("SELECT * FROM `styles` WHERE `locked`!='1' ORDER BY `id` DESC LIMIT 0, 50");

$q = $db->store_result();

if ( $q && $q->num_rows > 0 ){
	
	$ret['count'] = $q->num_rows;
	$ret['styles'] = array();
	
	while ( $arr = $q->fetch_array( MYSQLI_ASSOC ) )
	{
	
		if ( !file_exists( D_FOLDER.$arr['url']) && $arr['url'] != "def" ) continue;
		
		$ret['styles'][] = array( "id"=>$arr['id'],
									//"title"=>iconv("CP1251","UTF-8",$arr['title']),
									"title"=>$arr['title'],
									"url"=>D_SITE.$arr['url'],
									"preview"=>D_SITE.$arr['preview']);
	}
	
} else $ret['error'] = 1;


echo json_encode($ret);
